package com.wanmait.recycle.service.impl;


import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.recycle.mapper.FirsttypeMapper;
import com.wanmait.recycle.mapper.HistoryMapper;
import com.wanmait.recycle.mapper.SecondtypeMapper;
import com.wanmait.recycle.pojo.Firsttype;
import com.wanmait.recycle.pojo.History;
import com.wanmait.recycle.pojo.Rubbish;
import com.wanmait.recycle.pojo.Secondtype;
import com.wanmait.recycle.pojo.Userinfo;
import com.wanmait.recycle.service.ConfigService;
import com.wanmait.recycle.service.HistoryService;
import com.wanmait.recycle.util.PageContext;
import com.wanmait.recycle.util.Pager;
@Service
@Transactional
public class HistoryServiceImpl implements HistoryService {
	@Resource
	private ConfigService configService;
	@Resource
	private HistoryMapper historyMapper;
	@Resource
	private FirsttypeMapper firsttypeMapper;
	@Resource
	private SecondtypeMapper secondtypeMapper;
	@Override
	public void insert(History object) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void update(History object) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void delete(Integer id) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void delete(String ids) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public History findById(Integer id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<History> findAll() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int getDataCount() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<History> findAll(Pager pager) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<History> findAll(History object) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int getDataCount(History object) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<History> findAll(Pager pager, History object) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public PageInfo<History> findAllByPager() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<History> findByUserinfo(Userinfo user) {
		// TODO Auto-generated method stub
		return historyMapper.findByUserinfo(user);
	}

	@Override
	public void setUnEnableByTypeAndId(Integer type, Integer id) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setEnableByTypeAndId(Integer type, Integer id) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void addHistory(Integer type, Userinfo userinfo, Integer objectId,String objectName, Integer firsttypeid,
			Integer secondtypeId) {
		History history=new History();
		
		String content="";
		Firsttype ft=firsttypeMapper.selectByPrimaryKey(firsttypeid);
		if(type==1) {
				Secondtype st=secondtypeMapper.selectByPrimaryKey(secondtypeId);
				content+=ft.getTitle()+">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+st.getTitle()+">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+objectName;
		}
		else {
				content+=ft.getTitle()+">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+objectName;
		}
		history.setType(type);
		history.setContent(content);
		history.setUserinfo(userinfo);
		history.setObjectid(objectId);
		history.setStatus(0);
		Date date=new Date();
		Timestamp ts=new Timestamp(date.getTime());
		history.setInputTime(ts);
		historyMapper.insertNew(history);
	}

	@Override
	public void deleteByTypeAndObjectId(Integer type, Integer objectId) {
		// TODO Auto-generated method stub
		historyMapper.deleteByTypeAndObjectId(type,objectId);
	}

	@Override
	public PageInfo<History> findByUserinfoAndPageInfo(Userinfo user) {
		// TODO Auto-generated method stub
		
		Map<String, Map<String,String>> config = configService.findAllConfig();
		PageHelper.startPage(PageContext.getPageNum(), Integer.parseInt(config.get("前台分页").get("webPage")));
		List<History> history = historyMapper.findByUserinfo2(user);
		PageInfo<History> pageInfo = new PageInfo<History>(history,7);
		return pageInfo;
	}

}
